<dl class="drop-down-menu<?php if ($pathUrl === 0) echo ' selected'; ?>">
    <dt class="drop-down-menu__title">Каталог запчастей</dt>
    <dd class="drop-down-menu__content">
        <div class="drop-down-menu__content__inner">
            <ul class="drop-down-menu__list">                
                <?php
                $c = 0;
                foreach ($rows as $row):
                    ?>
                    <li class="drop-down-menu__list__item<?php if ($pathUrl <= 0 && $c == 0) echo ' selected'; ?><?php echo isset($pathUrl[0]) && $row['url'] == $pathUrl[0] ? ' selected' : ''; ?>">
                        <a href="#" class="drop-down-menu__list__link"><?php echo $row['title']; ?></a>
                        <dl class="drop-down-menu__list__tabs">
                            <?php if (isset($row['brands'])): ?>
                                <dt class="drop-down-menu__list__tabs__title<?php if ($pathUrl <= 0) echo ' selected'; ?>">
                                <span>По брендам</span>
                                </dt>
                                <dd class="drop-down-menu__list__tabs__content<?php if ($pathUrl <= 0) echo ' selected'; ?>">
                                    <div class="content scroll-simple scroll-simple_outer">
                                        <ul class="select-type">
                                            <?php foreach ($row['brands'] as $brand): ?>
                                                <li<?php echo isset($pathUrl[1]) && $brand['ch_url'] == $pathUrl[1] ? ' class="selected"' : ''; ?>>
                                                    <a href="/<?php echo $row['url'] . '/' . $brand['ch_url']; ?>"><?php echo $brand['ch_title']; ?></a>
                                                </li>
                                            <?php endforeach; ?>
                                        </ul>
                                    </div>  
                                </dd>
                            <?php endif; ?>
                            <?php if (isset($row['sp_type'])): ?>
                                <dt class="drop-down-menu__list__tabs__title">
                                <span>По типу з.ч.</span>
                                </dt>
                                <dd class="drop-down-menu__list__tabs__content">
                                    <div class="content scroll-simple scroll-simple_outer">
                                        <ul class="select-type">
                                            <?php foreach ($row['sp_type'] as $sp_type): ?>
                                                <li<?php echo isset($pathUrl[1]) && $sp_type['ch_url'] == $pathUrl[1] ? ' class="selected"' : ''; ?>>
                                                    <a href="/<?php echo $row['url'] . '/' . $sp_type['ch_url']; ?>"><?php echo $sp_type['ch_title']; ?></a>
                                                </li>
                                            <?php endforeach; ?>
                                        </ul>
                                    </div>  
                                </dd>
                            <?php endif; ?>
                        </dl>
                    </li>
                    <?php
                    $c++;
                endforeach;
                ?>
            </ul>
        </div>
    </dd>
</dl>

<script type='text/javascript'>
    $(document).ready(function () {
        var elem = $('.select-type li.selected');
        if (elem.text().length > 0) {
            elem.parents('.drop-down-menu__list__tabs__content').addClass('selected');
            elem.parents('.drop-down-menu__list__tabs__content').prev('.drop-down-menu__list__tabs__title').addClass('selected');
        }
    });
</script>